﻿using System;
using System.Collections.Generic;
using System.Text;
using AI.Fuzzy.Library;
using Sharp3DMath.Strokes;
using Sharp3DMath.Core;

namespace LRSS
{
    public class RecogniseMachine
    {
        
        private static FuzzyLogicSystemFactory SRFLS = new FuzzyLogicSystemFactory();
        private static MamdaniFuzzySystem _srfls = null;
       
        public static List<RuleResult> Recognise(Vector2F[] points)
        {
            if (_srfls == null)
            {
                _srfls = SRFLS.CreateSystem();
            }
            
            Stroke stroke = new Stroke(points);
            StrokeFeaturesBase featureBase = FeaturesGenerator.GetFeatures(points);          
            return Recognise(featureBase);
        }
        public static List<RuleResult> Recognise(StrokeFeaturesBase features)
        {
            if (_srfls == null)
            {
                _srfls = SRFLS.CreateSystem();
            }

            FuzzyVariable srHer_Wer = _srfls.InputByName("Her_Wer");
            FuzzyVariable srPch2_Ach4PI = _srfls.InputByName("Pch2_Ach4PI");
            FuzzyVariable srAlt_Ach = _srfls.InputByName("Alt_Ach");
            FuzzyVariable srAlt_Alq = _srfls.InputByName("Alt_Alq");
            FuzzyVariable srAch_Aer = _srfls.InputByName("Ach_Aer");
            FuzzyVariable srAlq_Aer = _srfls.InputByName("Alq_Aer");
            FuzzyVariable srHollowness = _srfls.InputByName("Hollowness");
            FuzzyVariable srTl_Pch = _srfls.InputByName("Tl_Pch");
            FuzzyVariable srAlq_Ach = _srfls.InputByName("Alq_Ach");
            FuzzyVariable srAlt_Aer = _srfls.InputByName("Alt_Aer");
            FuzzyVariable srPlq_Pch = _srfls.InputByName("Plq_Pch");


            FuzzyVariable srSharp = _srfls.OutputByName("Sharp");
            //
            // Associate input values with input variables
            //
            Dictionary<FuzzyVariable, double> inputValues = new Dictionary<FuzzyVariable, double>();
            inputValues.Add(srHer_Wer, features.Her_Wer);
            inputValues.Add(srPch2_Ach4PI, features.Pch2_Ach4PI);
            inputValues.Add(srAlt_Ach, features.Alt_Ach);
            inputValues.Add(srAlt_Alq, features.Alt_Alq);
            inputValues.Add(srAch_Aer, features.Ach_Aer);
            inputValues.Add(srAlq_Aer, features.Alq_Aer);
            inputValues.Add(srHollowness, features.Hollowness);
            inputValues.Add(srTl_Pch, features.Tl_Pch);
            inputValues.Add(srAlq_Ach, features.Alq_Ach);
            inputValues.Add(srAlt_Aer, features.Alt_Aer);
            inputValues.Add(srPlq_Pch, features.Plq_Pch);

            //Todo SharpResult 与 MyResult之间的转换
            return _srfls.LRSSCalculate(inputValues);
        }
    }
}
